﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Istace.Framework.Mapping.Core;
using Istace.Framework.Mapping.Core.Internal;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Istace.Framework.Mapping.UnitTest
{
    [TestClass]
    public class MappingTupleTest
    {
        [TestMethod]
        public void MappingTupleToStringShouldReturnCorrectlyFormatedStringForIndexing()
        {
            Mapper.Initialize(this.GetType().Assembly, false, true);
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.AreEqual(tuple.ToString(), String.Format("MapperOf{0}To{1}", typeof(string), typeof(string)));
        }

        [TestMethod]
        public void MappingTupleEqualMethodTest()
        {
            MappingTuple tuple1 = new MappingTuple(typeof(string), typeof(string));
            MappingTuple tuple2 = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(tuple1 == tuple2, "Equality comparaison for the same object fail.");

            tuple2 = new MappingTuple(typeof(int), typeof(string));
            Assert.IsFalse(tuple1 == tuple2, "Equality comparaison for the different object fail.");

            Assert.IsFalse(tuple1 == null, "Equality comparaison for null value object fail.");
            Assert.IsFalse(null == tuple1, "Equality comparaison for null value object fail.");
        }

        [TestMethod]
        public void MappingTupleGetHashCodeMethodTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            int hashCode = tuple.Source.GetHashCode() + tuple.Destination.GetHashCode();
            Assert.IsTrue(hashCode == tuple.GetHashCode());
        }


        [TestMethod]
        public void MappingTupleCompareToTest()
        {
            MappingTuple tuple1 = new MappingTuple(typeof(string), typeof(string));
            MappingTuple tuple2 = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(tuple1.CompareTo(tuple2) == 0);
        }

        [TestMethod]
        public void MappingTupleCompareToWithNullReturnMinusOne()
        {
            MappingTuple tuple1 = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(tuple1.CompareTo(null) == -1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void MappingTupleCompareToWithBadTypeThrowException()
        {
            MappingTuple tuple1 = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(tuple1.CompareTo("test") == -1);
        }

        [TestMethod]
        public void MappingTupleGreatherThanOperatorTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(!(tuple > tuple));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MappingTupleGreatherThanWithFirstArgumentNullOperatorTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(!(null > tuple));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MappingTupleGreatherThanWithSecondArgumentNullOperatorTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(!(tuple > null));
        }

        [TestMethod]
        public void MappingTupleLowerThanOperatorTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(!(tuple < tuple));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MappingTupleLowerThanWithFirstArgumentNullOperatorTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(!(null < tuple));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MappingTupleLowerThanWithSecondArgumentNullOperatorTest()
        {
            MappingTuple tuple = new MappingTuple(typeof(string), typeof(string));
            Assert.IsTrue(!(tuple < null));
        }

        [TestMethod]
        public void MappingTupleEqualsMethodTest()
        {
            MappingTuple tuple1 = new MappingTuple(typeof(string), typeof(string));
            MappingTuple tuple2 = tuple1;
            Assert.IsTrue(tuple1.Equals(tuple2));
        }
    }
}
